import unittest

from requests import session

from api.login import Login


class TestLogin(unittest.TestCase):

    # unittest的类的前置条件
    @classmethod
    def setUpClass(cls):
        cls.session = session()
        cls.login = Login()
        # print("类前置")

    # def setUp(self):
    #     print("方法前置")
    #
    # def tearDown(self):
    #     print("方法后置")

    @classmethod
    def tearDownClass(cls):
        cls.session.close()
        # print("类后置")

    def test01_login_success(self):
        # 准备登录接口数据
        login_data = {
            "keywords": "18888888888",
            "password": "123456a"
        }
        response = self.login.login(self.session, login_data)
        print(response.json())


    # 登陆失败,账号不存在
    def test02_login_fail_username_not_exist(self):
        login_data = {
            "keywords": "16666666666",
            "password": "123456a"
        }
        response = self.login.login(self.session, login_data)
        print(response.json())

    # 登陆失败,账号为空
    def test03_login_fail_username_empty(self):
        login_data = {
            "keywords": "",
            "password": "123456a"
        }
        response = self.login.login(self.session, login_data)
        print(response.json())

    # 登陆失败,密码为空
    def test04_login_fail_password_empty(self):
        login_data = {
            "keywords": "18888888888",
            "password": ""
        }
        response = self.login.login(self.session, login_data)
        print(response.json())

    # 登陆失败,密码错误
    def test05_login_fail_password_error(self):
        login_data = {
            "keywords": "18888888888",
            "password": "123"
        }
        response = self.login.login(self.session, login_data)
        print(response.json())

